/*
 * @copyright Copyright (c) 2010 Laboratório de Educação Cerebral. (http://www.educacaocerebral.com.br)
 *
 * This file is part of SoftVFC.
 *
 * SoftVFC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SoftVFC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SoftVFC.  If not, see <http://www.gnu.org/licenses/>.
 *
 * *********************
 *
 * Este arquivo é parte do programa SoftVFC.
 *
 * SoftVFC é um software livre; você pode redistribui-lo e/ou
 * modifica-lo dentro dos termos da Licença Pública Geral GNU como
 * publicada pela Fundação do Software Livre (FSF); na versão 3 da
 * Licença.
 *
 * Este programa é distribuido na esperança que possa ser util,
 * mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer
 * MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a
 * Licença Pública Geral GNU para maiores detalhes.
 *
 * Você deve ter recebido uma cópia da Licença Pública Geral GNU
 * junto com este programa, se não, acesse no website oficial:
 * http://www.gnu.org/licenses/gpl.html
 *
 */
package org.softvfc.daq.audiocapture;

import java.awt.GridLayout;
import java.io.FileNotFoundException;
import java.util.logging.Logger;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.openide.util.ImageUtilities;
import org.netbeans.api.settings.ConvertAsProperties;
import org.softvfc.daq.trace.CaptureWaveHeart;

/**
 *
 * @author Diego Schmaedech Martins (schmaedech@gmail.com)
 * @version 29/07/2010
 */
@ConvertAsProperties(dtd = "-//org.softvfc.daq.audiocapture//Capture//EN", autostore = false)
public final class CaptureTopComponent extends TopComponent {

    private static CaptureTopComponent instance;
    private static CaptureWaveHeart captureHeart = new CaptureWaveHeart();
    /** path to the icon used by the component and its open action */
    static final String ICON_PATH = "org/softvfc/daq/audiocapture/utilities-system-monitor.png";
    private static final String PREFERRED_ID = "CaptureTopComponent";

    public CaptureTopComponent() throws FileNotFoundException {
        initComponents();
        initAudioCapture();

        setName(NbBundle.getMessage(CaptureTopComponent.class, "CTL_CaptureTopComponent"));
        setToolTipText(NbBundle.getMessage(CaptureTopComponent.class, "HINT_CaptureTopComponent"));
        setIcon(ImageUtilities.loadImage(ICON_PATH, true));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpAudioCapture = new javax.swing.JPanel();

        javax.swing.GroupLayout jpAudioCaptureLayout = new javax.swing.GroupLayout(jpAudioCapture);
        jpAudioCapture.setLayout(jpAudioCaptureLayout);
        jpAudioCaptureLayout.setHorizontalGroup(
            jpAudioCaptureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 690, Short.MAX_VALUE)
        );
        jpAudioCaptureLayout.setVerticalGroup(
            jpAudioCaptureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 264, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpAudioCapture, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpAudioCapture, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void initAudioCapture() throws FileNotFoundException{
 
        getJpAudioCapture().setLayout( new GridLayout(0,1) );
        getJpAudioCapture().add( captureHeart );
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jpAudioCapture;
    // End of variables declaration//GEN-END:variables
    /**
     * Gets default instance. Do not use directly: reserved for *.settings files only,
     * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
     * To obtain the singleton instance, use {@link #findInstance}.
     */
    public static synchronized CaptureTopComponent getDefault() throws FileNotFoundException {
        if (instance == null) {
            instance = new CaptureTopComponent();
        }
        return instance;
    }

    /**
     * Obtain the CaptureTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized CaptureTopComponent findInstance() throws FileNotFoundException {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            Logger.getLogger(CaptureTopComponent.class.getName()).warning(
                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof CaptureTopComponent) {
            return (CaptureTopComponent) win;
        }
        Logger.getLogger(CaptureTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID
                + "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }

    @Override
    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_ALWAYS;
    }

    @Override
    public void componentOpened() {

    }

    @Override
    public void componentClosed() {
        
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    Object readProperties(java.util.Properties p) {
        if (instance == null) {
            instance = this;
        }
        instance.readPropertiesImpl(p);
        return instance;
    }

    private void readPropertiesImpl(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    @Override
    protected String preferredID() {
        return PREFERRED_ID;
    }

    /**
     * @return the jpAudioCapture
     */
    public javax.swing.JPanel getJpAudioCapture() {
        return jpAudioCapture;
    }

    /**
     * @param jpAudioCapture the jpAudioCapture to set
     */
    public void setJpAudioCapture(javax.swing.JPanel jpAudioCapture) {
        this.jpAudioCapture = jpAudioCapture;
    }

   
}
